var categoryArray = new Array();
var selectedCategoryField;

function generateCategries_o(categories, selectedCategory, changeMethod){
	if (selectedCategory == null){
		selectedCategory = 'ВСИЧКИ';
	}
	selectedCategoryField = selectedCategory;
	var result='<div class="topleft"></div>';
	result+='<div class="topmiddle"></div>';
	result+='<div class="topright"></div>';
	result+='<ul id="mycarousel" class="jcarousel-skin-tango">';
	if (categories != null){
		categoryArray = categories;
	}

	var className = 'categorynav';
	if (selectedCategory == 'ВСИЧКИ'){
		className = 'selected';
	}
	result+='<li class="'+className+'"><a href="#" onclick="'+changeMethod+'(\'ВСИЧКИ\');">ВСИЧКИ</a></li>';
	for(i=0; i<categoryArray.length;i++){
		if (categoryArray[i][0] == null){
			continue;
		}
		className = 'categorynav';
		if (selectedCategory.toUpperCase() == categoryArray[i][0].toUpperCase()){
			className = 'selected';
		}
		if(categoryArray[i].length > 1){
			result+='<li class="'+className+'"><a href="#" onclick="'+changeMethod+'(\''+categoryArray[i][0]+'\');">'+categoryArray[i][1].toUpperCase()+'</a></li>';
		} else {
			result+='<li class="'+className+'"><a href="#" onclick="'+changeMethod+'(\''+categoryArray[i].toString()+'\');">'+categoryArray[i].toString().toUpperCase()+'</a></li>';
		}
		
	}
	result+='<li></li>';
	result+='</ul>';
	document.getElementById("top").innerHTML = result;
	jQuery('#mycarousel').jcarousel({
        scroll : 6
    });
}

function generateCategries(categories, selectedCategory){
	generateCategries_o(categories, selectedCategory, 'changeCategory');
}


function changeCategory(catName){
	agent.call('','change_category','', catName);
	agent.call('','getComponents','up_callback');
	generateCategries(null, catName);
}
